package aplication;

import controller.util.Resolusao;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javafx.application.Application;
import static javafx.application.Application.launch;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;
import log.HandlerChangeHtml;

/*
 * Classe principal do Rotulador (MAIN)
 * STATIC
 *  LOGGER = faz instanciação principal do logger.. terá apenas essa..
 *  ROTULADOR = singleton..
 *  STAGE = palco principal...
 */
public class Rotulador extends Application {
    private static final Logger LOGGER = Logger.getLogger("rotulador.aplication");
    private static HandlerChangeHtml changeHtml = new HandlerChangeHtml();
    private static Rotulador instace;
    private static Stage stage;

    public Rotulador() {
        instace = this;
    }

    /*
     * @PARAN stage = é o palco principal criado pelo javaFx
     */
    @Override
    public void start(Stage stage) throws Exception {
        changeHtml.salve();
        Parent root = FXMLLoader.load(getClass().getResource("/view/Principal.fxml"));
        Scene scene = new Scene(root);
        Resolusao.getInstance().setResolucao(stage);
        stage.setScene(scene);
        stage.show();
        LOGGER.addHandler(HandlerChangeHtml.getFileHandler());
        LOGGER.log(Level.INFO, "Incio da aplicação, load Principal com suscesso");
        this.stage = stage;
    }

    /*
     * metodo chamado para atualizar a scene do palco principal...
     */
    public void setStage(Parent root) throws IOException {
        Scene scene = new Scene(root);
        stage.setScene(scene);
    }

    public static Rotulador getInstace() {
        return instace;
    }

    /*
     * main ta aki.. tadinha tem quase nada
     */
    public static void main(String[] args) {
        launch(args);
    }

    public static Stage getStage() {
        return stage;
    }

    public static Logger getLOGGER() {
        return LOGGER;
    }
    
    @Override
    public void stop() throws Exception {
        super.stop();
    }
}